﻿<script src="/static/ckeditor5/ckeditor.js"></script>
<script language="javascript" type="text/javascript" src="/static/js/jquery-1.11.1.min.js"></script>

<div class="placeholder-height"></div>
<div class="article-section-wrap">
    <div class="article-section">
        <div class="container">
            <div class="nrtj-wrap"></div>
            <div class="wrap-left pull-left">
                <form>
                    <div class="form-group">
                        <label for="article_title">标题：</label>
                        <input type="text" class="form-control" id="article_title" placeholder="请输入标题">
                    </div>
                    <div class="form-group">
                        <label for="article_category">分类：</label>
                        <select class="form-control" id="article_category">
                            <option selected value="电商消费">电商消费</option>
                            <option value="娱乐淘金">娱乐淘金</option>
                            <option value="雪花一代">雪花一代</option>
                            <option value="人工智能">人工智能</option>
                            <option value="智能终端">智能终端</option>
                            <option value="医疗健康">医疗健康</option>
                            <option value="金融地产">金融地产</option>
                            <option value="企业服务">企业服务</option>
                            <option value="创业维艰">创业维艰</option>
                            <option value="社交通讯">社交通讯</option>
                            <option value="全球热点">全球热点</option>
                            <option value="生活腔调">生活腔调</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="article_summary">文章摘要：</label>
                        <textarea class="form-control" rows="3" id="article_summary"></textarea>
                    </div>
                    <div class="form-group">
                        <label for="article_content">文章内容：</label>
                        <!-- 集成CKEditor -->
                        <textarea name="content" id="editor">
                        </textarea>
                    </div>
                    <br/>
                    <button type="button" class="btn btn-default" id="submit_article">提交并且保存</button>
                    <br/>
                    <br/>
                    <br/>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function() {
        $("#submit_article").click(function(){
            // 检查是否填写了标题、分类、摘要信息
            var article_title = $("#article_title").val()
            var article_category = $("#article_category").val()
            var article_summary = $("#article_summary").val()
            var article_content = article_editor.getData()
            if( !article_title || article_title == null || article_title == "" ){
                alert("新闻标题不允许为空！");
                $("#article_title").focus();
                return false;
            }
            if( !article_summary || article_summary == null || article_summary == "" ){
                alert("新闻摘要不允许为空！");
                $("#article_summary").focus();
                return false;
            }
            if( !article_content || article_content == null || article_content == "" ){
                alert("新闻内容不允许为空！");
                return false;
            }
            var data = {
                "article_title" : article_title,
                "article_category" : article_category,
                "article_summary" : article_summary,
                "article_content": article_content
            }
            var url = "home/article";
            send_post(url, data, function(json){
                if ("success" != json.status) {
                    alert( json.message );
                }else{
                    alert( json.message );
                    window.location.reload();
                }
            }, null)
        });
    });
    var article_editor = null;
    ClassicEditor
        .create( document.querySelector( '#editor' ) )
        .then( editor => {
        article_editor = editor; // 将编辑器赋值给一个全局变量，以便于操作
    } )
    .catch( error => {
        console.error( error );
    } );
</script>
<script type="text/javascript" src="/static/js/mouse.js"></script>
<style>
    .ck-editor__editable {
        min-height: 400px;
    }
</style>
</body>
</html>